package com.ruoyi.common.newAdd.utils;

import com.github.kevinsawicki.http.HttpRequest;

import java.nio.charset.StandardCharsets;
import java.util.Map;

public class Api {

    static String IP = "http://139.219.136.225:8081/zwy/api/";

    public static HttpRequest get(String url){
        HttpRequest request = HttpRequest.get(url);
        return request;
//        return getlss(url);
    }

    public static HttpRequest getToken(String url,String token){
        HttpRequest request = HttpRequest.get(url).header("token",token);
        return request;
    }

    public static HttpRequest getFromData(String url, Map<String,Object> data){
        HttpRequest request = HttpRequest.get(url).contentType("multipart/form-data").form(data);
        return request;
    }

    public static HttpRequest post(String url,String json){
        HttpRequest request = HttpRequest.post(url).contentType(HttpRequest.CONTENT_TYPE_JSON).send(json.getBytes(StandardCharsets.UTF_8));
        return request;
//        return postlss(url,json);
    }

    public static HttpRequest postJson(String url,String json){
        HttpRequest request = HttpRequest.post(url).contentType(HttpRequest.CONTENT_TYPE_JSON).send(json);
        return request;
//        return postlss(url,json);
    }

    public static HttpRequest post(String url){
        HttpRequest request = HttpRequest.post(url).contentType(HttpRequest.CONTENT_TYPE_JSON);
        return request;
//        return postlss(url);
    }

    public static HttpRequest postFromData(String url){
        HttpRequest request = HttpRequest.post(url).contentType("multipart/form-data");
        return request;
    }

    public static HttpRequest postToken(String url,String json,String token){
        HttpRequest request = HttpRequest.post(url).header("token",token).contentType(HttpRequest.CONTENT_TYPE_JSON).send(json.getBytes(StandardCharsets.UTF_8));
        return request;
    }

    public static HttpRequest getEE(String url){
        HttpRequest request = HttpRequest.get(url).header("User-Agent",
                "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");;
        return request;
    }

    /**
     * 以下为临时方法
     * @param url
     * @return
     */

    public static HttpRequest getlss(String url){
        String geturl = IP+"get?url="+url;
        System.out.println(geturl);
        HttpRequest request = HttpRequest.get(geturl);
        return request;
    }

    public static HttpRequest postlss(String url,String json){
        String posturl = IP+"posturljson?url="+url+"&json="+json;
        System.out.println(posturl);
        HttpRequest request = HttpRequest.get(posturl);
//        HttpRequest request = HttpRequest.post(url).contentType(HttpRequest.CONTENT_TYPE_JSON).send(json.getBytes(StandardCharsets.UTF_8));
        return request;
    }

    public static HttpRequest postlss(String url){
        String posturl = IP+"posturl?url="+url;
        System.out.println(posturl);
        HttpRequest request = HttpRequest.get(posturl);
//        HttpRequest request = HttpRequest.post(url).contentType(HttpRequest.CONTENT_TYPE_JSON);
        return request;
    }
}
